package com.ruoyi.cms.fileInfo.service.impl;

import com.ruoyi.cms.fileInfo.domain.FileClassAssign;
import com.ruoyi.cms.fileInfo.domain.SysFileInfo;
import com.ruoyi.cms.fileInfo.mapper.FileClassAssignMapper;
import com.ruoyi.cms.fileInfo.service.FileClassAssignInterface;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@AllArgsConstructor
public class FileClassAssignService implements FileClassAssignInterface {

    private final FileClassAssignMapper fileClassAssignMapper;

    @Override
    public FileClassAssign selectFileClassAssignById(Long id) {
        FileClassAssign fileClassAssign = new FileClassAssign();
        fileClassAssign.setId(id);
        return fileClassAssignMapper.selectFileClassAssignById(id);
    }

    @Override
    public List<FileClassAssign> selectFileClassAssignList(FileClassAssign fileClassAssign) {
        fileClassAssign.setFlag(UserConstants.YES);
        return fileClassAssignMapper.selectFileClassAssign(fileClassAssign);
    }

    @Override
    public List<FileClassAssign> selectFileClassAssignStudentList(FileClassAssign fileClassAssign) {
        int student = fileClassAssign.getStudent();
        return fileClassAssignMapper.selectFileClassAssignStudent(student);
    }

    @Override
    public int insertFileClassAssign(FileClassAssign fileClassAssign) {
        fileClassAssign.setFlag(UserConstants.YES);
        fileClassAssign.setCreateTime(DateUtils.getNowDate());
        return fileClassAssignMapper.insertFileClassAssign(fileClassAssign);
    }

    @Override
    public int insertFileClassAssign(SysFileInfo sysFileInfo) {
        FileClassAssign fileClassAssign = new FileClassAssign();
        BeanUtils.copyProperties(sysFileInfo, fileClassAssign);
        return insertFileClassAssign(fileClassAssign);
    }

    @Override
    public int updateFileClassAssign(Integer student, Long id) {
        FileClassAssign fileClassAssign = new FileClassAssign();
        fileClassAssign.setId(id);
        fileClassAssign.setStudent(student);
        return updateFileClassAssign(fileClassAssign);
    }

    @Override
    public int updateFileClassAssignNot(Long id) {
        FileClassAssign fileClassAssign = new FileClassAssign();
        fileClassAssign.setId(id);
        fileClassAssign.setFlag(UserConstants.NO);
        return updateFileClassAssign(fileClassAssign);
    }

    @Override
    public int updateFileClassAssign(FileClassAssign fileClassAssign) {
        fileClassAssign.setUpdateTime(DateUtils.getNowDate());
        return fileClassAssignMapper.updateFileClassAssign(fileClassAssign);
    }
}
